package com.uchengwang.functions.db.manager;

import android.content.Context;

import com.uchengwang.functions.db.dbBean.MsgAllowBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by U城网 on 2017/7/26.
 */

public class LiteOrmManager {

    private static LiteOrmManager manager;
    private LiteOrmManager (){}
    public static LiteOrmManager getManager() {
        if (manager == null){
            manager = new LiteOrmManager();
        }
        return manager;
    }


    /**
     * 查询一个ID有没有在消息免打扰的集合里
     * true 该ID在消息免打扰里 消息不允许响铃等
     * */
    public boolean isInMsgAllow(Context context, long id){
        List<MsgAllowBean> list = LiteOrmDBUtil.getLiteOrm(context).getQueryByWhere(MsgAllowBean.class, "uid", String.valueOf(id));
        if (list != null && list.size() >0){
            for (MsgAllowBean bean :list){
                if (id == bean.getUid()){
                    //在消息免打扰里
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 获取所有的免打扰集合
     * */
    public List<Long> getMsgAllowList(Context context){
        List<MsgAllowBean> list = LiteOrmDBUtil.getLiteOrm(context).getQueryAll(MsgAllowBean.class);
        List<Long> list1 = new ArrayList<>();
        if (list != null && list.size() >0){
            for (MsgAllowBean bean :list){
                list1.add(bean.getUid());
            }
        }
        return list1;
    }


}
